package com.huika.dealontop.control.shops.activity;

import android.animation.Animator;
import android.content.Intent;
import android.graphics.PointF;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.Response;
import com.google.gson.reflect.TypeToken;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.huika.dealontop.GlobalApp;
import com.huika.dealontop.R;
import com.huika.dealontop.anim.berzier.BezierTravelAnim;
import com.huika.dealontop.config.UrlConstants;
import com.huika.dealontop.control.base.extend.BaseActionBarActivity;
import com.huika.dealontop.control.homepage.database.DindanDbHelper;
import com.huika.dealontop.control.login.activity.LoginActivity;
import com.huika.dealontop.control.nearby.activity.GMapActivity;
import com.huika.dealontop.control.shops.adapter.ProductDetailFootAdapter;
import com.huika.dealontop.control.shops.fragment.OtherProductListFragment;
import com.huika.dealontop.control.shops.fragment.ProductEvaluationListFragment;
import com.huika.dealontop.control.shops.fragment.ProductNoticeFragment;
import com.huika.dealontop.control.shops.holder.ProductDetailHeaderHolder1;
import com.huika.dealontop.control.timelimit.activity.ShoppingCartAtc;
import com.huika.dealontop.control.timelimit.fragment.ShoppingCartFragment;
import com.huika.dealontop.support.domain.ProductDetailsBean;
import com.huika.dealontop.support.event.SelectShoppingCarEvent;
import com.huika.dealontop.support.http.FormResultRequest;
import com.huika.dealontop.support.http.JSONWrapAjaxParams;
import com.huika.dealontop.support.http.RequestResult;
import com.huika.dealontop.support.http.rsa.Base64Helper;
import com.huika.dealontop.utils.DebugTool;
import com.huika.dealontop.utils.FileTool;
import com.huika.dealontop.utils.ImageLoaderHelper;
import com.huika.dealontop.utils.LoginUtils;
import com.huika.dealontop.utils.SharpHelper;
import com.huika.dealontop.utils.UIUtils;
import com.huika.dealontop.views.CommonTitleRightWindow;
import com.huika.dealontop.views.HKScrollView;
import com.huika.dealontop.views.TBLayout;
import com.huika.dealontop.views.TabSlidingIndicator;
import com.huika.dealontop.views.ToastMsg;
import com.huika.huikalib.utils.MoneyShowTool;
import com.huika.sharpsdklib.Utils;

import java.io.UnsupportedEncodingException;
import java.util.Collections;

import de.greenrobot.event.EventBus;

/**
 * Author: Victor Wu <br/>
 * Email: victor-wu*foxmail.com <br/>
 * Time: 2015/11/20 12:05 <br/>
 * Description: 商品详情 (类似淘宝 上下分页显示 布局)
 */
public class ProductDetailsActivity1 extends BaseActionBarActivity implements TBLayout.OnPullListener, TBLayout.OnPageChangedListener, Response.Listener<RequestResult<ProductDetailsBean>> {
    public static final String PRODUCT_ID = "ProductId";
    public static final String PRODUCT_IMG = "ProductImage";
    public static final String SKU_ID = "SKU_ID";

    private String mProductId;
    private String mProductImage;
    private long mSKUId;
    private TBLayout mRootView;
    private HKScrollView mHeaderArea;
    private LinearLayout mFootArea;

    private ProductDetailHeaderHolder1 mHeaderHolder;
    private TabSlidingIndicator mIndicator;
    private ViewPager mVpFootContent;
    private ProductDetailFootAdapter mPageAdapter;

    private ProductDetailsBean mProductDetails;

    private LinearLayout mHeaderContent;

    private PullToRefreshListView mCurrLvContent;
    private SharpHelper sharpHelper;
    private ImageView mIvBackToTop;
    private ImageView mIvCart;
    private TextView mTvCartCount;
    private TextView mTvBuy;
    private TextView mTvAddToCart;
    private View mTitleBar;
    private ImageView mIvMenu;
    private int currPage = TBLayout.SCREEN_HEADER;

    private int cartProductCount;

    private CommonTitleRightWindow moreWindow;

    @Override
    protected void initData() {
        Intent intent = getIntent();
        if(intent != null){
            mProductId = intent.getStringExtra(PRODUCT_ID);
            mProductImage = intent.getStringExtra(PRODUCT_IMG);
            mSKUId = intent.getLongExtra(SKU_ID, -1);
        }
        super.initData();
    }

    @Override
    public void setRootView() {
        setContentView(R.layout.activity_product_details1);
    }

    @Override
    protected void initWidget() {
        //隐藏基类的标题
        getActionBarHelper().hideActionBar();

        //标题部分
        findViewById(R.id.iv_back).setOnClickListener(this);
        mIvMenu = (ImageView) findViewById(R.id.iv_menu);
        mIvMenu.setOnClickListener(this);
        mTitleBar = findViewById(R.id.rl_product_title);
        mTitleBar.setAlpha(0);
        moreWindow = new CommonTitleRightWindow(aty);

        //初始化整个详情布局
        mRootView = (TBLayout) findViewById(R.id.tblayout);
        mRootView.setOnPullListener(this);
        mRootView.setOnContentChangeListener(this);
        mRootView.setFutureChangePageListener(new FutureChangePageListener());

        //顶部基本信息区域
        mHeaderArea = (HKScrollView) mRootView.findViewById(R.id.tb_header);
        mHeaderArea.setOnScrollListener(new ProductDetailOnScrollListener());

        //底部
        mFootArea = (LinearLayout) mRootView.findViewById(R.id.tb_footer);
        mVpFootContent = (ViewPager) mRootView.findViewById(R.id.vp_product_detail_footContent);
        mVpFootContent.setOffscreenPageLimit(2);
        mIndicator = (TabSlidingIndicator) mRootView.findViewById(R.id.product_detail_indicator);

        mHeaderContent = (LinearLayout) mHeaderArea.getChildAt(0);
        mHeaderHolder = new ProductDetailHeaderHolder1(this, mHeaderContent);

        mTvBuy = (TextView) findViewById(R.id.tv_product_detail_buy);
        mTvBuy.setOnClickListener(this);
        mTvAddToCart = (TextView) findViewById(R.id.tv_product_detail_add_to_cart);
        mTvAddToCart.setOnClickListener(this);
        findViewById(R.id.iv_product_sharp).setOnClickListener(this);

        mIvBackToTop = (ImageView) findViewById(R.id.iv_back_to_top);
        mIvBackToTop.setOnClickListener(this);
        mIvCart = (ImageView) findViewById(R.id.iv_product_cart);
        mIvCart.setOnClickListener(this);
        mTvCartCount = (TextView) findViewById(R.id.tv_product_cart_count);

        startLoadData();

        if(mProductImage != null){
            ImageLoaderHelper.displayImage(mProductImage, (ImageView)findViewById(R.id.iv_product_init_img));
        }
    }

    @Override
    protected void onResume() {
        //购物车显示
        cartProductCount = GlobalApp.getCartProductNumber();
        refreshCartCount();

        //未查看消息
        checkHasMessage();
        super.onResume();
    }

    private void checkHasMessage() {
        findViewById(R.id.iv_has_msg).setVisibility(new DindanDbHelper().getUnUsedableCountNum() > 0 ? View.VISIBLE : View.GONE);
    }

    private void startLoadData() {
        JSONWrapAjaxParams ajaxParams = new JSONWrapAjaxParams();
        ajaxParams.putCommonTypeParam("ProductId", mProductId);
        ajaxParams.putCommonTypeParam("Lang", UIUtils.getString(R.string.common_lang));
        FormResultRequest<ProductDetailsBean> productRequest = new FormResultRequest(UrlConstants.PRODUCT_DETAIL, this, this,
                new TypeToken<RequestResult<ProductDetailsBean>>() {
                }.getType());
        productRequest.setRequestParams(ajaxParams);
        showLoadingDialog("");
        executeRequest(productRequest);

    }

    @Override
    public void onResponse(RequestResult<ProductDetailsBean> requestResult) {
        dismissLoadingDialog();
        if (requestResult != null && (mProductDetails = requestResult.getRs()) != null) {
            //排序 和 设置默认的套餐
            int initIndex = initPackageList();
            //显示头部数据
            mHeaderHolder.setData(mProductDetails, initIndex);

            //初始化viewpage
            initFootPage();

            initStatus(mProductDetails.getProduct());

        }
    }

    private void initStatus(ProductDetailsBean.ProductBean product) {
        if(product == null)return;
        mTvBuy.setEnabled(product.getStatus() != 5);
        mTvAddToCart.setEnabled(product.getStatus() != 5);
        //已下架 提示
        findViewById(R.id.tv_shelves_remind).setVisibility(product.getStatus() == 5 ? View.VISIBLE : View.GONE);
        //预售商品 提示
        findViewById(R.id.LL_presell_remind).setVisibility(product.isSale() ? View.VISIBLE : View.GONE);
    }

    /**
     * 初始化 分栏页面
     */
    private void initFootPage() {
        if(mProductDetails == null) return;

        mPageAdapter = new ProductDetailFootAdapter(getSupportFragmentManager());
        mPageAdapter.setProductDetails(mProductDetails);
        mVpFootContent.setAdapter(mPageAdapter);
        //
        mIndicator.setViewPager(mVpFootContent);
        mIndicator.setOnPageChangeListener(new OnProductPageChangeListener());
        //打开第一页
        mVpFootContent.setCurrentItem(0);
    }

    /**
     * 排序 和 设置默认的套餐
     * @return
     */
    private int initPackageList() {
        int packageIndex = 0;
        if(mProductDetails.getPackageSelect() != null
                && mProductDetails.getPackageSelect().size() > 0){
            //按套餐价格从低到高 排序
            Collections.sort(mProductDetails.getPackageSelect());

            //获取进来详情页面是指定的套餐
            ProductDetailsBean.PackageSelectBean  packageItem = null;
            if(mSKUId != -1){
                for (int i = 0; i < mProductDetails.getPackageSelect().size(); i++) {
                    if(mProductDetails.getPackageSelect().get(i).getSKU_ProducId() == mSKUId){
                        packageItem = mProductDetails.getPackageSelect().get(i);
                        packageIndex = i;
                    }
                }
            }
            if(packageItem == null){
                //如果没有指定的套餐 就 显示第一个套餐的价格 和折扣
                packageItem  = mProductDetails.getPackageSelect().get(0);
                packageIndex = 0;
            }

            if(mProductDetails.getProduct() != null){
                mProductDetails.getProduct().setSalePrice(packageItem.getSkuHKPrice());
                mProductDetails.getProduct().setDiscount(packageItem.getDiscount());
            }
        }
        return packageIndex;
    }

    private ProductDetailsBean.PackageSelectBean getPackageSelectBean() {
        if(mSKUId != -1){
            for (ProductDetailsBean.PackageSelectBean packageSelect : mProductDetails.getPackageSelect() ) {
                if(packageSelect.getSKU_ProducId() == mSKUId){
                    return packageSelect;
                }
            }
        }
        return null;
    }

    @Override
    public void widgetClick(View v) {
        int id = v.getId();
        if(id == R.id.tv_product_detail_buy || id == R.id.tv_product_detail_add_to_cart){
            ProductDetailsBean.ProductBean productBean;
            if (mProductDetails == null || (productBean = mProductDetails.getProduct()) == null) {
                return;
            }
            ProductDetailsBean.PackageSelectBean packageSelectBean = mHeaderHolder.getPackage();
            if(packageSelectBean == null || packageSelectBean.getStock() < 1){
                ToastMsg.showToastMsg(this, UIUtils.getString(R.string.under_stock));
                return;
            }
            if(id == R.id.tv_product_detail_buy){
                Intent intent = new Intent(this, SubmitOrderActivity.class);
                intent.putExtra(GMapActivity.MERCHANTNAME, productBean.getProductName());

                intent.putExtra(UseBonusActivity.CITYID, productBean.getCityId());
                if(packageSelectBean != null){
                    intent.putExtra(SubmitOrderActivity.PRODUCT_SKUID, packageSelectBean.getSKU_ProducId());
                    intent.putExtra(SubmitOrderActivity.PRODUCT_SKUNAME,packageSelectBean.getSkuName());
                    intent.putExtra(SubmitOrderActivity.PRODUCT_STOCK, packageSelectBean.getStock());
                    intent.putExtra(SubmitOrderActivity.SKUPRICE, packageSelectBean.getSkuHKPrice());
                }
                showActivity(this, intent);
            } else if(v.getId() == R.id.tv_product_detail_add_to_cart){
                if (LoginUtils.isLogin()) {
                    addToCart(packageSelectBean);
                } else {
                    showActivity(this, LoginActivity.class);
                }
            }
        }
        else if(v.getId() == R.id.iv_product_sharp){
            showSharpDialog();
        }
        else if(v.getId() == R.id.iv_back_to_top){
            mRootView.scrollToHeader();
            mHeaderArea.fullScroll(ScrollView.FOCUS_UP); //滚动到顶部
            mTitleBar.setAlpha(0);
        }
        else if(v.getId() == R.id.iv_back){
            finish();
        }
        else if(v.getId() == R.id.iv_menu){
            moreWindow.showWindow(mIvMenu, - UIUtils.dip2px(110), 0);
        }
        else if(v.getId() == R.id.iv_product_cart){
            Intent intent1 = new Intent(this,ShoppingCartAtc.class);
            intent1.putExtra(ShoppingCartFragment.TYPETITLE,1);
            showActivity(this, intent1);
        }
        super.widgetClick(v);
    }

    /**
     * 添加商品到购物车
     */
    private void addToCart(ProductDetailsBean.PackageSelectBean packageSelectBean) {
        JSONWrapAjaxParams ajaxParams = new JSONWrapAjaxParams();
        ajaxParams.putCommonTypeParam("userId", GlobalApp.getInstance().getUserId());
        ajaxParams.putCommonTypeParam("SkuProductId", packageSelectBean.getSKU_ProducId());
        ajaxParams.putCommonTypeParam("Quantity", 1);
        FormResultRequest<Integer> loginRequest = new FormResultRequest(UrlConstants.ADD_TO_CART,
                new Add2CartRequestListener(),
                this,
                new TypeToken<RequestResult<Integer>>() {
                }.getType());
        loginRequest.setRequestParams(ajaxParams);
//        showLoadingDialog(UIUtils.getString(R.string.add_to_cart));
        showLoadingDialog("");
        executeRequest(loginRequest);
    }

    /**
     * 加入购物车接口回调
     */
    class Add2CartRequestListener implements Response.Listener<RequestResult<Integer>>{
        @Override
        public void onResponse(RequestResult<Integer> integerRequestResult) {
            dismissLoadingDialog();
            if(integerRequestResult !=  null && integerRequestResult.flag == 1){
                ToastMsg.showToastMsg(getBaseContext(), UIUtils.getString(R.string.successfully_added_to_cart));
                cartProductCount = integerRequestResult.getRs();
                playAddToCartAnim();
                /* ***************
                 * 通知购物车数量
                 ****************/
                EventBus.getDefault().post(new SelectShoppingCarEvent(""));
                return;
            }
            ToastMsg.showToastMsg(getBaseContext(), UIUtils.getString(R.string.failed_to_add_to_Cart));
        }
    }

    /**
     * 播放加入购物车动画
     */
    private void playAddToCartAnim() {
        int[] location = new int[2];
        mRootView.getLocationOnScreen(location);
        PointF startP = new PointF();
        startP.x = location[0];
        startP.y = location[1];

        mIvCart.getLocationOnScreen(location);
        PointF endP = new PointF();
        endP.x = location[0] + UIUtils.dip2px(15);
        endP.y = location[1] + UIUtils.dip2px(15);

        ViewGroup animView = (ViewGroup) View.inflate(getBaseContext(), R.layout.cart_anim, null);
        if(mProductDetails.getProductPicUrlList() != null && mProductDetails.getProductPicUrlList().size() > 0){
            ImageLoaderHelper.displayImage(mProductDetails.getProductPicUrlList().get(0), (ImageView)animView.getChildAt(0));
        }

        BezierTravelAnim travelAnim = new BezierTravelAnim.Builder(this)
                .setAnimView(animView)
                .setStartPointF(startP)
                .setEndPointF(endP)
                .setDuration(1000)
                .setAnimatorListener(new AddToCartAnimatorListener())
                .build();

        travelAnim.startAnimation();
    }

    class AddToCartAnimatorListener implements Animator.AnimatorListener{
        @Override
        public void onAnimationStart(Animator animator) {}
        @Override
        public void onAnimationCancel(Animator animator) {}
        @Override
        public void onAnimationRepeat(Animator animator) {}
        @Override
        public void onAnimationEnd(Animator animator) {
            //更新购物车数量
            refreshCartCount();
        }
    }

    /**
     * 刷新购物车数量显示
     */
    private void refreshCartCount() {
        mTvCartCount.setVisibility(cartProductCount > 0 ? View.VISIBLE : View.GONE);
        mTvCartCount.setText(String.valueOf(cartProductCount));
    }

    /**
     * 显示分享对话框
     */
    private void showSharpDialog() {
        if (sharpHelper == null) {
            String title = null;
            String price = null;
            String shareCode = GlobalApp.getInstance().getUserReferralCode();
            String productId = null;
            if (mProductDetails != null && mProductDetails.getProduct() != null) {
                ProductDetailsBean.ProductBean productBean = mProductDetails.getProduct();
                title = productBean.getProductName();
                price = MoneyShowTool.nolastDF(productBean.getSalePrice());
                productId = String.valueOf(productBean.getProductId());
            }
            if (TextUtils.isEmpty(price) || TextUtils.isEmpty(productId)) {
                return;
            }

            String url = getShareUrl(shareCode, productId);
            String content = getSharpContent(title, price, url);

            sharpHelper = new SharpHelper(ProductDetailsActivity1.this,
                    title,
                    url,
                    content,
                    null);
            sharpHelper.setOnClickSharpIconListener(new SharpHelper.OnClickSharpIconListener() {
                @Override
                public void onClickSharp(View view) {
//                            if (view.getId() == R.id.iv_sharp_copy) {
//                                ClipboardHelper.copy(content, UIUtils.getContext());
//                                ToastMsg.showToastMsg(UIUtils.getContext(), UIUtils.getString(R.string.copy_success));
//                            } else
                    if (view.getId() == R.id.iv_sharp_cut) {
                        try {
                            String path = Utils.saveViewToImage(mRootView);
                            FileTool.refreshAlbum(ProductDetailsActivity1.this, path);
                            Toast.makeText(UIUtils.getContext(), UIUtils.getString(R.string.save_image_to_album), Toast.LENGTH_LONG).show();
                        } catch (Throwable throwable) {
                            ToastMsg.showToastMsg(UIUtils.getContext(), UIUtils.getString(R.string.cut_screen_failure));
                            throwable.printStackTrace();
                        }
                    }
                }
            });
        }
        sharpHelper.show();
    }

    class OnProductPageChangeListener implements ViewPager.OnPageChangeListener {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }
        @Override
        public void onPageScrollStateChanged(int state) {
        }
        @Override
        public void onPageSelected(int position) {
            if(currPage != TBLayout.SCREEN_FOOTER){
                //如果当前显示的区域不是底部分栏部分，不加载数据，避免初始化viewPage时也加载数据
                return;
            }
            if (position == 0) {
                //选中才加载网络数据
                ((OtherProductListFragment) mPageAdapter.getItem(position)).firstLoadData();
            } else if (position == 1) {
                //选中才加载网络数据
                ((ProductEvaluationListFragment) mPageAdapter.getItem(position)).firstLoadData();
            } else if (position == 2) {
                //须知页面不需要加载数据
            }
        }

    }

    class FutureChangePageListener implements TBLayout.OnFutureChangePageListener {
        @Override
        public void onFutureChangePage(int stub) {
            if(mHeaderHolder != null){
                if(TBLayout.SCREEN_FOOTER == stub){
                    if(stub == currPage){
                        mHeaderHolder.setMarkedWords(UIUtils.getString(R.string.pull_down_to_details));
                    }else {
                        mHeaderHolder.setMarkedWords(UIUtils.getString(R.string.release_to_graphic_details));
                    }
                }else if(TBLayout.SCREEN_HEADER == stub){
                    if(stub == currPage){
                        mHeaderHolder.setMarkedWords(UIUtils.getString(R.string.pull_up_to_graphic_details));
                    }else {
                        mHeaderHolder.setMarkedWords(UIUtils.getString(R.string.release_to_details));
                    }
                }
            }
        }
    }

    @Override
    public boolean headerFootReached(MotionEvent event) {
        if (mHeaderArea.getScrollY() + mHeaderArea.getHeight() >= mHeaderContent
                .getHeight()) {
            return true;
        }
        return false;
    }

    @Override
    public boolean footerHeadReached(MotionEvent event) {
        int index =  mVpFootContent.getCurrentItem();
        if(index == 0){
            mCurrLvContent = ((OtherProductListFragment)mPageAdapter.getItem(0)).getPullToRefreshListView();
            if (mCurrLvContent.getRefreshableView().getFirstVisiblePosition() == 0) {
                View v = mCurrLvContent.getChildAt(0);
                if (v != null && v.getTop() == 0) {
                    return true;
                }
            } else if (mCurrLvContent.getVisibility() == View.GONE) {
                return true;
            }
        }else if(index == 1){
            mCurrLvContent = ((ProductEvaluationListFragment)mPageAdapter.getItem(1)).getPullToRefreshListView();
            if (mCurrLvContent.getRefreshableView().getFirstVisiblePosition() == 0) {
                View v = mCurrLvContent.getChildAt(0);
                if (v != null && v.getTop() == 0) {
                    return true;
                }
            } else if (mCurrLvContent.getVisibility() == View.GONE) {
                return true;
            }
        }else if(index == 2){
            if (((ProductNoticeFragment)mPageAdapter.getItem(2)).getScrollView().getScrollY() == 0) {
                return true;
            }
        }
        return false;
    }

    private boolean fristOpenFoot = true;
    @Override
    public void onPageChanged(int stub) {
        currPage = stub;
        switch (stub) {
            case TBLayout.SCREEN_HEADER:
                Log.d("tag", "SCREEN_HEADER");
                mIvBackToTop.setVisibility(View.GONE);
                if(mHeaderHolder != null){
                    mHeaderHolder.setMarkedWords(UIUtils.getString(R.string.pull_up_to_graphic_details));
                }
                if(mFootArea != null){
//                    LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) mFootArea.getLayoutParams();
//                    params.setMargins(0, 0, 0, 0);
//                    mFootArea.setLayoutParams(params);
                    mFootArea.setPadding(0, 0, 0, 0);
                }
                break;
            case TBLayout.SCREEN_FOOTER:
                Log.d("tag", "SCREEN_FOOTER");
                mIvBackToTop.setVisibility(View.VISIBLE);
                if(mHeaderHolder != null){
                    mHeaderHolder.setMarkedWords(UIUtils.getString(R.string.pull_down_to_details));
                }
                if(mFootArea != null){
//                    LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) mFootArea.getLayoutParams();
//                    params.setMargins(0, UIUtils.dip2px(44) - 1, 0, 0);
//                    mFootArea.setLayoutParams(params);
                    mFootArea.setPadding(0, UIUtils.dip2px(44) - 1, 0, 0);
                }
                if(fristOpenFoot){
                    //第一次打开 底部分栏页面是，默认选中第一页，并加载数据
                    fristOpenFoot = false;
                    mVpFootContent.setCurrentItem(0);
                    ((OtherProductListFragment)mPageAdapter.getItem(0)).firstLoadData();
                }
                break;
        }
    }

    class ProductDetailOnScrollListener implements HKScrollView.OnScrollListener {
        /**
         * 滚动的回调方法
         */
        @Override
        public void onScroll(int scrollY) {
            float a = scrollY / ((float)UIUtils.dip2px(260 - 44));
            DebugTool.i("scrollY","scrollY : " + scrollY + " a : " + a);

            if(a < 0){
                a = 0;
            } else if(a > 1){
                a = 1;
            }
            mTitleBar.setAlpha(a); //[0,1]
        }
    }

    private String getSharpContent(String title, String price, String url){
        return UIUtils.getFormatString(R.string.sharp_content,title,price,url);
    }

    private String getShareUrl(String shareCode, String productId) {
        String url = null;
        try {
            url = UrlConstants.HOST + "html5/show.html?shareCode=" + shareCode + "&ProductId=" + Base64Helper.encode(productId.getBytes("utf-8")) + "&lang=" + UIUtils.getString(R.string.common_lang);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return url;
    }

}
